//
//  LCBarView.m
//  EnterpriseCloud
//
//  Created by 东亨 on 2017/7/11.
//  Copyright © 2017年 lichao. All rights reserved.
//

#import "LCBarView.h"

@interface LCBarView ()
@property (strong,nonatomic)NSArray *titleArr;
@end

@implementation LCBarView
- (instancetype)init
{
    self = [super init];
    if (self)
    {
        self.backgroundColor = [UIColor colorWithHex:0xf6f6f6];
        CGFloat height = (self.titleArr.count+1)*10+self.titleArr.count*30;
        self.bounds = CGRectMake(0, 0, 115, height);
        UIButton *conBtn = nil;
        for (int i = 0; i < self.titleArr.count; i++)
        {
            UIButton *contentBtn = ({
                UIButton *button = [[UIButton alloc]init];
                [self addSubview:button];
                [button mas_makeConstraints:^(MASConstraintMaker *make) {
                    make.top.equalTo(conBtn ? conBtn.mas_bottom : self.mas_top).offset(conBtn ? 10:10);
                    make.centerX.equalTo(self);
                }];
                button;
            });
            conBtn = contentBtn;
            conBtn.tag = i+1;
            contentBtn.titleLabel.font = [UIFont systemFontOfSize:17.0f];
            [contentBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
            [contentBtn setTitle:self.titleArr[i] forState:UIControlStateNormal];
            [contentBtn addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
        }
    }
    return self;
}
- (void)buttonClick:(UIButton *)sender
{
    if (_btnClickBlock)
    {
        _btnClickBlock(sender.tag);
    }
}
- (NSArray *)titleArr
{
    if (!_titleArr)
    {
        _titleArr = @[@"活动报名"];
    }
    return _titleArr;
}
@end
